home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / texdraw.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  9.4 KB  |  357 lines

  1. /*
  2.  * $Id: texdraw.trm,v 1.6 1995/12/20 21:48:15 drd Exp $
  3.  */
  4.  
  5. /* GNUPLOT - texdraw.trm */
  6. /*
  7.  * Copyright (C) 1990
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted,
  11.  * provided that the above copyright notice appear in all copies and
  12.  * that both that copyright notice and this permission notice appear
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed
  17.  * as patches to released version.
  18.  *
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  *
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   The TEXDRAW macros for LaTeX.
  25.  *
  26.  * AUTHORS
  27.  *   Khun Yee Fung. Modified from eepic.trm.
  28.  *   clipper@csd.uwo.ca
  29.  *   January 20, 1992
  30.  *
  31.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  32.  *
  33.  */
  34.  
  35. /*
  36.  *  This file contains the texdraw terminal driver, intended for use with the
  37.  *  texdraw macro package for LaTeX. This is an alternative to the
  38.  *  latex driver. You need texdraw.sty, and texdraw.tex in the texdraw package.
  39.  *
  40.  */
  41. #ifndef GOT_DRIVER_H
  42. #include "driver.h"
  43. #endif
  44.  
  45. #ifdef TERM_REGISTER
  46. register_term(texdraw)
  47. #endif
  48.  
  49. #ifdef TERM_PROTO
  50. TERM_PUBLIC void TEXDRAW_init __P((void));
  51. TERM_PUBLIC void TEXDRAW_graphics __P((void));
  52. TERM_PUBLIC void TEXDRAW_text __P((void));
  53. TERM_PUBLIC void TEXDRAW_linetype __P((int linetype));
  54. TERM_PUBLIC void TEXDRAW_move __P((unsigned int x, unsigned int y));
  55. TERM_PUBLIC void TEXDRAW_point __P((unsigned int x, unsigned int y, int number));
  56. TERM_PUBLIC void TEXDRAW_vector __P((unsigned int ux, unsigned int uy));
  57. TERM_PUBLIC void TEXDRAW_arrow __P((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, TBOOLEAN head));
  58. TERM_PUBLIC void TEXDRAW_put_text __P((unsigned int x, unsigned int y, char str[]));
  59. TERM_PUBLIC int TEXDRAW_justify_text __P((enum JUSTIFY mode));
  60. TERM_PUBLIC int TEXDRAW_text_angle __P((int angle));
  61. TERM_PUBLIC void TEXDRAW_reset __P((void));
  62.  
  63. #define TEXDRAW_PTS_PER_INCH (72.27)
  64. #define DOTS_PER_INCH (300)    /* resolution of printer we expect to use */
  65. #define TEXDRAW_UNIT (TEXDRAW_PTS_PER_INCH/DOTS_PER_INCH) /* dot size in pt */
  66.  
  67. /* 5 inches wide by 3 inches high (default) */
  68. #define TEXDRAW_XMAX (5*DOTS_PER_INCH)
  69. #define TEXDRAW_YMAX (3*DOTS_PER_INCH)
  70.  
  71. #define TEXDRAW_HTIC (5*DOTS_PER_INCH/72)    /* (5./TEXDRAW_UNIT) */
  72. #define TEXDRAW_VTIC (5*DOTS_PER_INCH/72)    /* (5./TEXDRAW_UNIT) */
  73. #define TEXDRAW_HCHAR (DOTS_PER_INCH*53/10/72)    /* (5.3/TEXDRAW_UNIT) */
  74. #define TEXDRAW_VCHAR (DOTS_PER_INCH*11/72)    /* (11./TEXDRAW_UNIT) */
  75.  
  76. #define GOT_TEXDRAW_PROTO
  77. #endif
  78.  
  79. #ifndef TERM_PROTO_ONLY
  80. #ifdef TERM_BODY
  81. static void TEXDRAW_endline __P((void));
  82. static unsigned int TEXDRAW_posx;
  83. static unsigned int TEXDRAW_posy;
  84. enum JUSTIFY TEXDRAW_justify = LEFT;
  85. enum JUSTIFY TEXDRAW_last_justify = LEFT;
  86. static int TEXDRAW_angle = 0;
  87. static float TEXDRAW_scalefactor = 0.2409;
  88. static double TEXDRAW_xscale = 1.0, TEXDRAW_yscale = 1.0;
  89.  
  90. /* for DOTS point style */
  91. #define TEXDRAW_TINY_DOT "\\htext{$\\cdot$}"
  92.  
  93. /* POINTS */
  94. #define TEXDRAW_POINT_TYPES 12    /* we supply more point types */
  95. static char GPFAR * GPFAR TEXDRAW_points[] =
  96. {
  97.   "\\rmove(0 4)\\htext{$\\Diamond$}",
  98.   "\\htext{$+$}",
  99.   "\\rmove(0 4)\\htext{$\\Box$}",
  100.   "\\htext{$\\times$}",
  101.   "\\htext{$\\triangle$}",
  102.   "\\htext{$\\star$}",
  103.   "\\lcir f:9",
  104.   "\\lcir f:12",
  105.   "\\lcir f:16",
  106.   "\\fcir f:0.9 r:9",
  107.   "\\fcir f:0.9 r:12",
  108.   "\\fcir f:0.9 r:16"
  109. };
  110.  
  111. /* LINES */
  112. #define TEXDRAW_NUMLINES 5    /* number of linetypes below */
  113. static int TEXDRAW_lines[] =
  114. {
  115.   4,        /* -2 border */
  116.   3,        /* -1 axes */
  117.   3,        /*  0 solid thin  */
  118.   4,        /*  1 solid thick */
  119.   6,        /*  2 solid Thick */
  120. };
  121.  
  122. static int TEXDRAW_last_type = 0; /* The line type selected most recently */
  123. static int TEXDRAW_type;    /* current line type */
  124. static TBOOLEAN TEXDRAW_inline = FALSE;    /* are we in the middle of a line */
  125. static void TEXDRAW_endline();    /* terminate any line in progress */
  126. static int TEXDRAW_linecount = 0;    /* number of points in line so far */
  127. #define TEXDRAW_LINEMAX 5    /* max value for linecount */
  128.  
  129. TERM_PUBLIC void TEXDRAW_init()
  130. {
  131.   TEXDRAW_posx = TEXDRAW_posy = 0;
  132.   TEXDRAW_linetype(-1);
  133.   fprintf(outfile, "%% GNUPLOT: LaTeX using TEXDRAW macros\n");
  134. }
  135.  
  136. TERM_PUBLIC void TEXDRAW_graphics()
  137. {
  138. static char GPFAR tdg1[] = "\
  139. \\begin{texdraw}\n\
  140. \\normalsize\n\
  141. \\ifx\\pathDEFINED\\relax\\else\\let\\pathDEFINED\\relax\n\
  142.  \\def\\QtGfr{\\ifx (\\TGre \\let\\YhetT\\cpath\\else\\let\\YhetT\\relax\\fi\\YhetT}\n\
  143.  \\def\\path (#1 #2){\\move (#1 #2)\\futurelet\\TGre\\QtGfr}\n\
  144.  \\def\\cpath (#1 #2){\\lvec (#1 #2)\\futurelet\\TGre\\QtGfr}\n\
  145. \\fi\n\
  146. \\drawdim pt\n\
  147. \\setunitscale %2.2f\n\
  148. \\linewd %d\n\
  149. \\textref h:L v:C\n";
  150.   fprintf(outfile, tdg1, 
  151.     TEXDRAW_scalefactor,
  152.     TEXDRAW_lines[2]);
  153.   TEXDRAW_last_type = 0;
  154.   TEXDRAW_type = 0;
  155. }
  156.  
  157. TERM_PUBLIC void TEXDRAW_text()
  158. {
  159.   TEXDRAW_endline();
  160.   fprintf(outfile, "\\end{texdraw}\n");
  161. }
  162.  
  163. TERM_PUBLIC void TEXDRAW_linetype(linetype)
  164. int linetype;
  165. {
  166.   TEXDRAW_endline();
  167.  
  168.   if (linetype >= TEXDRAW_NUMLINES - 2)
  169.     linetype %= (TEXDRAW_NUMLINES - 2);
  170.  
  171.   TEXDRAW_type = linetype;
  172. }
  173.  
  174. TERM_PUBLIC void TEXDRAW_move(x, y)
  175. unsigned int x, y;
  176. {
  177.   TEXDRAW_endline();
  178.  
  179.   TEXDRAW_posx = x;
  180.   TEXDRAW_posy = y;
  181. }
  182.  
  183. TERM_PUBLIC void TEXDRAW_point(x, y, number)
  184. unsigned int x, y;
  185. int number;
  186. {
  187.   TEXDRAW_move(x, y);
  188.  
  189.   /* Print the character defined by 'number'; number < 0 means
  190.         to use a dot, otherwise one of the defined points. */
  191.   fprintf(outfile, "\\move (%d %d)\n",
  192.       (int)((double) x * TEXDRAW_xscale),
  193.       (int)((double) y * TEXDRAW_yscale));
  194.   if (TEXDRAW_last_justify != CENTRE) {
  195.     fprintf(outfile, "\\textref h:C v:C ");
  196.     TEXDRAW_last_justify = CENTRE;
  197.   }
  198.   fprintf(outfile, "%s\n",
  199.       (number < 0 ?
  200.        TEXDRAW_TINY_DOT :
  201.        TEXDRAW_points[number % TEXDRAW_POINT_TYPES]));
  202. }
  203.  
  204. TERM_PUBLIC void TEXDRAW_vector(ux, uy)
  205. unsigned int ux, uy;
  206. {
  207.   if (!TEXDRAW_inline) {
  208.     TEXDRAW_inline = TRUE;
  209.  
  210.     /* Start a new line. This depends on line type */
  211.     if (TEXDRAW_type != TEXDRAW_last_type){
  212.       if (TEXDRAW_lines[TEXDRAW_type+2] != TEXDRAW_lines[TEXDRAW_last_type+2])
  213.     fprintf(outfile, "\\linewd %d\n", TEXDRAW_lines[TEXDRAW_type + 2]);
  214.       TEXDRAW_last_type = TEXDRAW_type;
  215.     }
  216.     fprintf(outfile, "\\path (%d %d)",
  217.         (int)((double) TEXDRAW_posx * TEXDRAW_xscale),
  218.         (int)((double) TEXDRAW_posy * TEXDRAW_yscale));
  219.     TEXDRAW_linecount = 1;
  220.   }
  221.   else {
  222.     /* Even though we are in middle of a path,
  223.      * we may want to start a new path command.
  224.      * If they are too long then latex will choke.
  225.      */
  226.     if (TEXDRAW_linecount++ >= TEXDRAW_LINEMAX) {
  227.       fprintf(outfile, "\n\\cpath ");
  228.       TEXDRAW_linecount = 1;
  229.     }
  230.   }
  231.   fprintf(outfile, "(%d %d)",
  232.       (int)((double) ux * TEXDRAW_xscale),
  233.       (int)((double) uy * TEXDRAW_yscale));
  234.   TEXDRAW_posx = ux;
  235.   TEXDRAW_posy = uy;
  236. }
  237.  
  238. static void TEXDRAW_endline()
  239. {
  240.   if (TEXDRAW_inline) {
  241.     fprintf(outfile, "\n");
  242.     TEXDRAW_inline = FALSE;
  243.   }
  244. }
  245.  
  246. TERM_PUBLIC void TEXDRAW_arrow(sx, sy, ex, ey, head)
  247. unsigned int sx, sy, ex, ey;
  248. TBOOLEAN head;
  249. {
  250.   char text;
  251.  
  252.   if (head)
  253.     text = 'a';
  254.   else
  255.     text = 'l';
  256.   fprintf(outfile, "\\move (%d %d)\\%cvec (%d %d)",
  257.       (int)((double) sx * TEXDRAW_xscale),
  258.       (int)((double) sy * TEXDRAW_yscale),
  259.       text,
  260.       (int)((double) ex * TEXDRAW_xscale),
  261.       (int)((double) ey * TEXDRAW_yscale));
  262.   TEXDRAW_posx = ex;
  263.   TEXDRAW_posy = ey;
  264. }
  265.  
  266. TERM_PUBLIC void TEXDRAW_put_text(x, y, str)
  267. unsigned int x, y;        /* reference point of string */
  268. char str[];            /* the text */
  269. {
  270.   char text;
  271.  
  272.   TEXDRAW_endline();
  273.  
  274.   fprintf(outfile, "\\move (%d %d)",
  275.       (int)((double) x * TEXDRAW_xscale),
  276.       (int)((double) y * TEXDRAW_yscale));
  277.  
  278.   if (!TEXDRAW_angle)
  279.     text = 'h';
  280.   else
  281.     text = 'v';
  282.  
  283.   if (TEXDRAW_last_justify != TEXDRAW_justify) {
  284.     TEXDRAW_last_justify = TEXDRAW_justify;
  285.     if (TEXDRAW_justify == LEFT)
  286.       fprintf(outfile, "\\textref h:L v:C ");
  287.     else if (TEXDRAW_justify == CENTRE)
  288.       fprintf(outfile, "\\textref h:C v:C ");
  289.     else if (TEXDRAW_justify == RIGHT)
  290.       fprintf(outfile, "\\textref h:R v:C ");
  291.   }
  292.   fprintf(outfile, "\\%ctext{%s}\n", text, str);
  293. }
  294.  
  295.  
  296. TERM_PUBLIC int TEXDRAW_justify_text(mode)
  297. enum JUSTIFY mode;
  298. {
  299.   TEXDRAW_justify = mode;
  300.   return (TRUE);
  301. }
  302.  
  303. TERM_PUBLIC int TEXDRAW_text_angle(angle)
  304. int angle;
  305. {
  306.   TEXDRAW_angle = angle;
  307.   return (TRUE);
  308. }
  309.  
  310. TERM_PUBLIC void TEXDRAW_reset()
  311. {
  312.   TEXDRAW_endline();
  313.   TEXDRAW_posx = TEXDRAW_posy = 0;
  314. }   
  315.  
  316. #endif /* TERM_BODY */
  317.  
  318. #ifdef TERM_TABLE
  319.  
  320. TERM_TABLE_START(texdraw_driver)
  321.  
  322.     "texdraw",
  323.     "LaTeX texdraw environment",
  324.     TEXDRAW_XMAX, TEXDRAW_YMAX, TEXDRAW_VCHAR, TEXDRAW_HCHAR,
  325.     TEXDRAW_VTIC, TEXDRAW_HTIC, options_null, TEXDRAW_init, TEXDRAW_reset,
  326.     TEXDRAW_text, null_scale, TEXDRAW_graphics, TEXDRAW_move, TEXDRAW_vector,
  327.     TEXDRAW_linetype, TEXDRAW_put_text, TEXDRAW_text_angle,
  328.     TEXDRAW_justify_text, TEXDRAW_point, TEXDRAW_arrow, set_font_null
  329.  
  330. TERM_TABLE_END(texdraw_driver)
  331.  
  332. #undef LAST_TERM
  333.  
  334. #define LAST_TERM texdraw_driver
  335.  
  336. #endif /* TERM_TABLE */
  337.  
  338. #endif /* TERM_PROTO_ONLY */
  339.  
  340. /*
  341.  * NAME: texdraw
  342.  *
  343.  * OPTIONS: none
  344.  *
  345.  * SUPPORTS: LaTeX texdraw environment 
  346.  *
  347.  * Further Info: 
  348.  *
  349.  *  This terminal driver is intended for use with the
  350.  *  texdraw macro package for LaTeX. This is an alternative to the
  351.  *  latex driver. You need texdraw.sty, and texdraw.tex in the texdraw package.
  352.  *
  353.  *        My notes:
  354.  * Again I'm not sure whether this package works together with LaTeX 2e
  355.  * and isn't allready obsolete.
  356.  */
  357.